package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.FilterItem;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/14.
 */

public class UsermanagerGridViewAdapterHuanBing extends BaseAdapter {
    private static Map<Integer, Boolean> isSelected;
    Context context;
    List<FilterItem> data;
    int mSelect = -1;
    public UsermanagerGridViewAdapterHuanBing(Context context, List<FilterItem> data) {
        this.context = context;
        this.data = data;
        isSelected = new HashMap<Integer, Boolean>();
        for (int i = 0; i <data.size(); i++) {
            isSelected.put(i, false);
        }
    }
    public Map<Integer, Boolean> getIsSelected() {
        return isSelected;
    }

    public void setIsSelected(Map<Integer, Boolean> map) {
        UsermanagerGridViewAdapterHuanBing.isSelected = map;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.fragment_gridview_item,null);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.fragment_gridview_item_tv);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(data.get(position).getItemName().toString());
//        holder.textView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (isSelected.get(position)){
//                    isSelected.put(position,false);
//                    setIsSelected(isSelected);
//                    notifyDataSetChanged();
//                }else {
//                    isSelected.put(position,true);
//                    setIsSelected(isSelected);
//                    notifyDataSetChanged();
//                }
//            }
//        });
        if (isSelected.get(position))
        {
            holder.textView.setBackgroundResource(R.drawable.fragment_gridview_item_back2);
            holder.textView.setTextColor(context.getResources().getColor(R.color.light_blue));
        }else {
            holder.textView.setTextColor(context.getResources().getColor(R.color.colorGridViewTextViews));
            holder.textView.setBackgroundResource(R.drawable.fragment_gridview_item_back1);
        }
        return convertView;
    }
    static class ViewHolder{
        TextView textView = null;
    }
}
